//# sourceURL=userDetail.js
layui.element.on('tab(login-user-tabs)', function (layui_obj) {
    var custom_obj = $('#tabTitles')[0].children[layui_obj.index].tabCustomObj;
    var old_user_roles, old_phone;
    var platformApplyUserDetail_fn = {
        initRender: function () {
            //设置动态tab页内容主体的高度
            cmsUtils.setContentTabHeight('platformApplyUserDetailContent', 50);
            $('#platformApplyUserDetail').attr('hasRender', true);
            if (custom_obj.id) {
                var url = '/applyUser/platformApplyUserDetail/'+custom_obj.id;
                $.get(url, function (data) {
                    console.log(data);
                    platformApplyUserDetail_fn.setFormData(data);
                });
            }
        },
        setFormData: function (data) {
            cmsUtils.formDataBind('platformApplyUserDetail-form', data.data);
            $("#platformApplyUserDetail-jobRecord").val(data.data.jobRecord);
            $("#platformApplyUserDetail-personStrength").val(data.data.personStrength);
        },
        getFormData: function (data) {

        },
        submitForm: function (post_params, action, index) {
            var post_url = custom_obj.id ? '/cms/sysManage/editUser' : '/cms/sysManage/addUser';
            $.ajax({
                type: 'post',
                url: post_url,
                data: post_params,
                dataType: 'json',
                success: function (data) {
                    layer.close(index);
                    if (data.code == 200) {
                        switch (action) {
                            case 'continue':
                                $('#platformApplyUserDetail-form')[0].reset();
                                break;
                            case 'close':
                                layui.element.tabDelete('login-user-tabs', 'tab-platformApplyUserDetail');
                                custom_obj.list_fn.reload();
                                break;
                        }
                    } else {
                        layer.msg(data.msg, {anim: 6});
                    }
                }
            });
        }
    }
    if ($('#platformApplyUserDetail')[0] && !$('#platformApplyUserDetail').attr('hasRender')) {
        platformApplyUserDetail_fn.initRender();
        // 设置页面高度
        $(window).resize(function() {
            cmsUtils.setContentTabHeight('platformApplyUserDetailContent', 50);
        });
    }

    // 修改
    layui.form.on('submit(platformApplyUserDetail-btn-modify)', function (data) {
        if (!platformApplyUserDetail_fn.verifyForm()) {
            return;
        }
        var msg = '确定保存修改信息？';
        if (data.field.phone != old_phone) {
            msg = '确定修改联系方式？修改后平台短信消息都将发送至新手机号！';
        }
        layer.confirm(msg, {
            btn:['确定', '取消']
        }, function (index) {
            platformApplyUserDetail_fn.submitForm(platformApplyUserDetail_fn.getFormData(data.field), 'close', index);
        });
    });
});